package com.baosight.sczx.common.zm.cInterface.cs;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.spring.SpringApplicationContext;
import com.baosight.iplat4j.dao.Dao;

/**
 * 变量组
 * <p>Title: VariableGroup.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 严洪浩
 * @version 1.0
 * <pre>Histroy:
 *          2011-6-2 上午01:43:06  严洪浩  Create
 *</pre>
 */
public class VariableGroup {
	
	private static Dao dao = (Dao)SpringApplicationContext.getBean("dao");
	
	/**
	 * 矿井建模 构造树
	 * <p>Function: getMineTree</p>
	 * <p>Description: </p>
	 * <p>return value:List<Map></p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-2上午01:44:04 严洪浩
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static List<Map> getVariableGroupTree(Map<String, String> _argMap, boolean isShowAll){
		_argMap = _argMap == null ? new HashMap<String, String>():_argMap;
		
		if(isShowAll) {
			_argMap.put("fdStatus", "在用");
		}
		
		List<Map>  _list = new ArrayList();
		try {
			_list = dao.query("ZMCSVariableGroup.queryTree", _argMap);
		} catch (Exception e) {
			
		}
		return _list;
	}
	
	/**
	 * 判断变量组下是否有变量
	 * <p>Function: hasChildren</p>
	 * <p>Description: </p>
	 * <p>return value:boolean</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-8上午10:42:15 严洪浩
	 * </p>
	 *
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static boolean hasChildren(Map<String,List<String>> _argMap, EiInfo eiInfo) {
		_argMap = _argMap == null ? new HashMap<String, List<String>>():_argMap;
		
		List<Map>  _list = new ArrayList();
		
		try {
			_list = dao.query("ZMCSVariableGroup.validateHasChildren", _argMap);
			if(_list.size() < 1) {
				return false;
			}
			else {
				eiInfo.setStatus(-1);
				eiInfo.setMsg("该变量组下有变量，不能删除！");
			}
		} catch (Exception e) {
			System.out.println("验证变量组下是否存在变量异常: " + e.getMessage());
		}
		
		return true;
	}
}
